/*
 * Copyright (C) 2009 aileron.cc
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package cc.aileron.anime;

import javax.swing.JFrame;

import cc.aileron.anime.controller.WiimoteController;
import cc.aileron.anime.controller.WindowController;

import com.google.inject.Binder;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;

/**
 * @author Aileron
 * 
 */
public class Main
{
    /**
     * @param args
     * @throws Exception
     */
    public static void main(final String[] args) throws Exception
    {
        new Main().startup();
    }

    /**
     * @throws Exception
     */
    public void startup() throws Exception
    {
        context.mainFrame.setVisible(true);
    }

    /**
     * main
     * 
     * @throws Exception
     */
    public Main() throws Exception
    {
        final ApplicationContext context = this.context = new ApplicationContext();
        final Injector injector = Guice.createInjector(new Module()
        {
            @Override
            public void configure(final Binder binder)
            {
                binder.bind(JFrame.class)
                    .toInstance(context.mainFrame);
                binder.bind(ApplicationContext.class)
                    .toInstance(context);
            }
        });
        context.wiimote.addWiiMoteEventListeners(injector.getInstance(WiimoteController.class));
        context.mainFrame.addWindowListener(injector.getInstance(WindowController.class));
    }

    private final ApplicationContext context;
}
